<?php
namespace Wap\Controller;
use Wap\Controller\CommonController;
class ZixunController extends CommonController {

    /**
      +----------------------------------------------------------
     * 首页
     *
      +----------------------------------------------------------
     */
    public function index() {

    $User = M('show'); // 实例化User对象
 
    $count = $User->count();// 查询满足要求的总记录数
   
    $Page = new \Think\Page($count,9);// 实例化分页类 传入总记录数和每页显示的记录数(25)
  
    //$Page -> setConfig('theme','   %LINK_PAGE%  %FIRST%  %UP_PAGE%  %DOWN_PAGE%   %END% %HEADER%');
    $Page -> setConfig('first','首页');
    $Page -> setConfig('last','末页');
    $Page -> setConfig('prev','上一页');
    $Page -> setConfig('next','下一页');

    $Page -> setConfig('theme',' <div style="margin-top:2px">  %FIRST%  %UP_PAGE%    %LINK_PAGE%  %DOWN_PAGE%   %END%  </div> ');


      

        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $User->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $list6 = $User->order(array("yuedu"=>"desc"))->limit(9)->select();

      
        $this->assign('list6',$list6);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
              



        $this->display(); // 输出模板


    }



    public function detail(){
              $id= I('get.id');
              $m=M('show');
              $zixun=$m->where(array('id'=>$id))->find();
              $yuedu = $zixun["yuedu"]+1;

              $zixun["yuedu"] = $yuedu;

              $m->where(array("id"=>$id))->save(array("yuedu"=>$yuedu));


               $preinfo=$m->where('id<'.$id)->order('id desc' )->find();//上一条产品
               //var_dump($m->_sql());
               $preinfo['url']=U('Zixun/detail',array('id'=>$preinfo['id']));
                $nextinfo=$m->where('id>'.$id)->find();//下一条产品
                $nextinfo['url']=U('Zixun/detail',array('id'=>$nextinfo['id'])); 
           $this->assign('preinfo',$preinfo);
           $this->assign('nextinfo',$nextinfo);

          $this->assign('zixun',$zixun);




      $this->display();
    }


function sms(){
$result1=M("user")->where(array('phone'=>$_POST["phone"]))->find();

if ($result1=="") {
$phone=I('post.phone');
$code = rand(100000,999999);
$_SESSION['codedd']=$code;
$data ="【润格股份】您好，您的验证码是{$code},请输入您的验证码完成注册!5分钟内有效。";

$post_data = array();
$post_data['un'] ="N3759426";//账号
$post_data['pw'] = "N2lag5bKt";//密码
$post_data['msg']=$data; 
$post_data['phone'] =$phone;//手机
$post_data['rd']=1;

$url='http://sms.253.com/msg/send'; 
$res=$this->http_request($url,http_build_query($post_data));
echo $res;
}else{
  echo 0;
}


}


function xiugai(){
$result1=M("user")->where(array('phone'=>$_POST["phone"]))->find();

if ($result1=="") {
echo 0;
}else{
  
$phone=I('post.phone');
$code = rand(100000,999999);
$_SESSION['xiugai']=$code;
$data ="【润格股份】您好，您的验证码是{$code},请输入您的验证码完成密码修改!5分钟内有效。";

$post_data = array();
$post_data['un'] ="N3759426";//账号
$post_data['pw'] = "N2lag5bKt";//密码
$post_data['msg']=$data; 
$post_data['phone'] =$phone;//手机
$post_data['rd']=1;

$url='http://sms.253.com/msg/send'; 
$res=$this->http_request($url,http_build_query($post_data));
echo $res;

}


}


function http_request($url,$data = null){
  
  if(function_exists('curl_init')){
    $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
     
      if (!empty($data)){
          curl_setopt($curl, CURLOPT_POST, 1);
          curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
      }
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      $output = curl_exec($curl);
      curl_close($curl);
    
  
    $result=preg_split("/[,\r\n]/",$output);

    if($result[1]==0){
        return "1";
    }else{
        return "curl error".$result[1];
    }
  }elseif(function_exists('file_get_contents')){
    
    $output=file_get_contents($url.$data);
    $result=preg_split("/[,\r\n]/",$output);
  
    if($result[1]==0){
        return "1";
    }else{
        return "error".$result[1];
    }
    
    
  }else{
    return false;
  } 
  
}




  public function search(){

          $list=M('zlist')->select();
          
          $huxing=M('huxing')->order('id asc')->select();
          
          $fengge = I("get.fengge");
       $huxing1 = I("get.huxing");
       $where = "";

       if(!empty($fengge)){
          $data = M('zlist')->where("id = $fengge")->find();
          if(empty($where)){
            $where .= "a.fengge = '".$data['type_name']."'";
          }else{
            $where .= " and a.fengge = '".$data['type_name']."'";
          }
          
           
       }

       if(!empty($huxing1)){
          $data1 = M('huxing')->where("id=$huxing1")->find();
          if(empty($where)){
            $where .= "a.huxing = '".$data1['huxing']."'";
          }else{
            $where .= " and a.huxing = '".$data1['huxing']."'";
          }
       }
       
       $title=I('post.title');
         $map['a.name'] =array('like',"%$title%");
          $map['a.fengge'] =array('like',"%$title%");
          $map['a.huxing'] =array('like',"%$title%");
          $map['_logic'] = 'or';
    $shangpin=M('shangpin')->alias("a")->field("a.id,a.name,a.fengge,a.huxing,a.area,a.price,a.intro,a.img,a.userid,b.user as username")->join("zyb_user b on b.id = a.userid")->where($map)->order("a.id desc")->select();
         
            $this->assign("fengge",$fengge);
      $this->assign('list',$list);
      $this->assign('huxing',$huxing);
      $this->assign('huxing1',$huxing1);
            $this->assign('shangpin',$shangpin);
            $this->display();
        
    } 











   
}    
 
?>
 
